using IQIGame.Onigao.Game;
using IQIGame.Onigao.GamePlay;

namespace IQIGame.Onigao.Logic
{
    /// <summary>
    /// 改变执行次数
    /// 参数：1：实体tag（填0表示自己），2：修改类型（0：全量，1：增量），3：目标值
    /// </summary>
    public class ExecChangeExecutionCounts : BaseServiceExecution
    {
        public override void Execute(LevelRegion region, LevelPlayer player)
        {
            var config = _config as ExecParamChangeExecutionCounts;
            var entities = ListPool<LevelEntity>.Get();
            if (!LgLevelEntityUtil.GetEntitiesByDynCfgKeys(region, triggerEntity, config.tagOrMcid, entities))
            {
                ListPool<LevelEntity>.Put(entities);
                return;
            }
            int type = config.type;
            int value = config.value;

            foreach (LevelEntity entity in entities)
            {
                if (type == 0)
                {
                    entity.execCount = value;
                }
                else if (type == 1)
                {
                    entity.execCount += value;
                }
            }

            region.UpdateEntities(player, entities);

            ListPool<LevelEntity>.Put(entities);
        }
    }
}

